//
//  MOGestureView.m
//  WCImApp
//
//  Created by macMini on 2019/11/26.
//  Copyright © 2019 WCImApp. All rights reserved.
//

#import "MOGestureView.h"

@implementation MOGestureView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    
    
    /*
     直接拖动UISlider，此时touch时间在150ms以内，UIScrollView会认为是拖动自己，从而拦截了event，导致UISlider接受不到滑动的event。但是只要按住UISlider一会再拖动，此时此时touch时间超过150ms，因此滑动的event会发送到UISlider上。
    */
    UIView *view = [super hitTest:point withEvent:event];
    
    if([view isKindOfClass:[UISlider class]])
    {
        //如果响应view是UISlider,则移除滑动手势
        [self removeGestureRecognizer:self.panPress];
    }
    else
    {   //如果不是,则恢复滑动手势
        [self addGestureRecognizer:self.panPress];
    }
    return view;
}
- (void)panAction:(UIPanGestureRecognizer *)gestureRecognizer{
    if ([self.delegate respondsToSelector:@selector(interactiveTransitionRecognizerAction:)]) {
        [self.delegate interactiveTransitionRecognizerAction:self.panPress];
    }
}
- (UIPanGestureRecognizer *)panPress{
    if (!_panPress) {
        _panPress = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)];
    }
    return _panPress;
}
@end
